package com.baoyanghui.servlet.merchant;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import com.baoyanghui.common.InterfaceAccess;

/**
 * Servlet implementation class CheckUserId
 */
public class CheckUserId extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CheckUserId() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		JSONObject result;
		int code = 0;
		Map<String, String> params = new HashMap<String, String>();
		
		try {
			request.setCharacterEncoding("UTF-8");
			params.put("merchant_id", request.getParameter("user_id"));

			result = InterfaceAccess.callInterface("/merchant/check_user_id", params);
			code = result.getInt("code");
		} catch (IOException e) {
		}
		
		if (code == 0) {
			response.getWriter().write("true");
		} else {
			response.getWriter().write("false");
		}
	}

}
